package com.example.smartcity_poverty.ui.AllService.JobSearch

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.ui.AllService.JobSearch.fragment.JobSearchFragment
import com.example.smartcity_poverty.ui.AllService.JobSearch.fragment.JobSearchFragment.Companion.jobSearchId
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.android.synthetic.main.activity_job_search.*

/**
 * 找工作模块开发
 */
class JobSearchActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_job_search)
        title = "找工作"

        val tab = jsHomeTabLayout
        val vp = jsHomeViewPager2


        vp.adapter = object : FragmentStateAdapter(this) {
            override fun getItemCount(): Int = 3

            override fun createFragment(position: Int): Fragment = when (position) {
                0 -> JobSearchFragment()
                1 -> JobSearchFragment()
                else -> JobSearchFragment()
            }

            override fun getItemId(position: Int): Long {
                jobSearchId = when (position) {
                    0 -> 10
                    1 -> 20
                    else -> 30
                }
                return super.getItemId(position)
            }
        }



        TabLayoutMediator(tab, vp) { tab1, position ->
            when (position) {
                0 -> tab1.text = "找工作"
                1 -> tab1.text = "投递记录"
                else -> tab1.text = "个人简历"
            }
        }.attach()

    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}